/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-09-22 15:22:26
 * @LastEditors: 商晓彬
 * @LastEditTime: 2022-01-04 14:39:34
 */
import { LazyLoadEvent } from 'primeng/api';
import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { MessageService } from '@abp/message/message.service';
import { CommonServiceProxy, StoreFunctionsServiceProxy,PartsDeliveryServiceProxy } from '@shared/service-proxies/service-proxies';
import { finalize } from 'rxjs/operators';
import { AddShowResumeComponent } from '../warehousing/add-show-resume/add-show-resume.component';
import { AddExComponent } from '../ex-warehouse/add-ex/add-ex.component';
import { ReturnWarehouseComponent } from '../ex-warehouse/return-warehouse/return-warehouse.component';


@Component({
    selector: 'app-ex-warehouse-record',
    templateUrl: './ex-warehouse-record.component.html',
    styleUrls: ['./ex-warehouse-record.component.less']
})
export class ExWarehouseRecordComponent extends AppComponentBase {
    @ViewChild('paginator') paginator: Paginator;
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('AddShowResumeComponent') AddShowResumeComponent: AddShowResumeComponent;
    @ViewChild('ReturnWarehouseComponent') ReturnWarehouseComponent: ReturnWarehouseComponent;
    @ViewChild('AddExComponent') AddExComponent: AddExComponent;
    exNo = undefined;
    stroeName = undefined;
    stroeNameOptions = [];
    assemblyTaskNumber = undefined;
    qualifiedTaskNumber = undefined;
    releaseOrder = undefined;
    model = undefined;
    modelOptions = [];
    sendTime = undefined;
    sendTimeOptions = [];
    rowdata: any;
    checktype = undefined;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _commonServiceProxy: CommonServiceProxy,
        private _storeFunctionsServiceProxy: StoreFunctionsServiceProxy,
        private _partsDeliveryServiceProxy: PartsDeliveryServiceProxy,
    ) {
        super(injector);
    }
    openUrl() {
        window.open('http://10.20.253.4:8057/#/app/material/log');
    }
    watch(row) {
        this.checktype = 4;
        if (row.cancellingDesc == "新增退库") {
            setTimeout(() => {
                this.rowdata = row;
                this.AddExComponent.show();
            }, 5);
        } else {
            setTimeout(() => {
                this.rowdata = row;
                this.ReturnWarehouseComponent.show();
            }, 5);
        }
    }
    lookResume(row) {
        this.rowdata = row;
        setTimeout(() => {
            this.AddShowResumeComponent.show();
            this.AddShowResumeComponent.getTableList();
        }, 10);
    }
    reset() {
        this.exNo = undefined;
        this.stroeName = undefined;
        this.assemblyTaskNumber = undefined;
        this.qualifiedTaskNumber = undefined;
        this.releaseOrder = undefined;
        this.model = undefined;
        this.sendTime = undefined;
    }
    getTableList(event?: LazyLoadEvent) {
        let modlueName = undefined;
        let lotNoName = undefined;
        if (this.model != undefined) {
            for (const item of this.modelOptions) {
                if (item.value == this.model) {
                    modlueName = item.lable;
                }
            }
        }
        if (this.sendTime != undefined) {
            for (const item of this.sendTimeOptions) {
                if (item.value == this.sendTime) {
                    lotNoName = item.lable;
                }
            }
        }
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }
        this._partsDeliveryServiceProxy.getLibraryRetrievals(
            this.exNo,
            this.stroeName,
            this.assemblyTaskNumber,
            this.releaseOrder,
            this.qualifiedTaskNumber,
            modlueName,
            lotNoName,
            this.model,
            this.sendTime,
            this.primengTableHelper.getSorting(this.dataTable),
            this.primengTableHelper.getMaxResultCount(this.paginator, event),
            this.primengTableHelper.getSkipCount(this.paginator, event)
        ).pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
            this.primengTableHelper.totalRecordsCount = result.totalCount;
            this.primengTableHelper.records = result.items;
            this.primengTableHelper.hideLoadingIndicator();
        });
    }
    ngOnInit() {
        //仓库名称
        this._storeFunctionsServiceProxy.getStoreDropList(
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.stroeNameOptions = [];
                this.stroeNameOptions = result;
            });
        //型号
        this._commonServiceProxy.getModelList(
        )
            .pipe(finalize(() => { })).subscribe(result => {
                this.modelOptions = result;
            })
    }
    onChange(event) {
         //发次
        this._commonServiceProxy.getLotNoList(
             this.model
            )
                .pipe(finalize(() => { })).subscribe(result => {
                    this.sendTimeOptions = result;
                })
    }
}
